package com.ada.base.common;

import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 通用响应结果实体类
 * 
 * @author 王巨壁
 *
 */
@Data
public class ResultData implements Serializable {

	private static final long serialVersionUID = 2469653664994097540L;
	
	private Integer code; // 结果编码:0000成功
	
	private String msg; // 响应消息
	
	private Object data;

	public static final Integer SUCCESS_CODE = 0;
	public static final String SUCCESS_CODE_MSG = "成功";

	public static final Integer FAIL_CODE = -1;
	public static final String FAIL_CODE_MSG = "失败";

	//返回成功 ;
	public static ResultData successResult(Object object) {
		ResultData tResultData = new ResultData();
		tResultData.setCode(SUCCESS_CODE);
		tResultData.setMsg(SUCCESS_CODE_MSG);
		tResultData.setData(object);
		return tResultData;
	}

	public static ResultData successResult(String key,Object value) {
		Map<String, Object> result = new HashMap<>();
		result.put(key, value);
		ResultData tResultData = new ResultData();
		tResultData.setCode(SUCCESS_CODE);
		tResultData.setMsg(SUCCESS_CODE_MSG);
		tResultData.setData(result);
		return tResultData;
	}


	//返回失败
 	public static ResultData failResult(String errorMsg) {
		ResultData tResultData = new ResultData();
		tResultData.setCode(FAIL_CODE);
		tResultData.setMsg(errorMsg);
		return tResultData;
	}

	//返回失败
	public static ResultData failResult(String errorMsg,Object data) {
		ResultData tResultData = new ResultData();
		tResultData.setCode(FAIL_CODE);
		tResultData.setMsg(FAIL_CODE_MSG);
		tResultData.setData(data);
		return tResultData;
	}
}
